<template>
  <div class="edu-form-input-number">
    <el-input-number
      v-model="current_field"
      :min="$util.getDefValue(current_args.min, 1)"
      :max="$util.getDefValue(current_args.max, 999999)"
      :step="$util.getDefValue(current_args.step, 1)"
      :precision="$util.getDefValue(current_args.precision, 0)"
      :controls-position="controls_position"
      :placeholder="$util.getDefValue(current_args.placeholder, '')"
      size="medium"
      :disabled="disabledValue"
    />
  </div>
</template>
<script>
export default {
  props: {
    value: {
      type: String,
      default: ''
    },
    args: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      current_field: this.value,
      current_args: this.args
    };
  },
  computed: {
    disabledValue() {
      if (this.current_args.disabled == '1') {
        return true;
      }

      return null;
    },
    controls_position() {
      return this.current_args.controls_position ? this.current_args.controls_position : null;
    }
  },
  watch: {
    current_field(value) {
      this.$emit('update:value', value);
    },
    value: {
      handler(now, old) {
        this.current_field = now;
      }
    }
  }
};
</script>
<style scoped>
.edu-form-input-number {
  max-width: 600px;
}
</style>
